package com.cskaoyan.gateway.controller.shopping;

import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.shopping.IHomeService;
import com.mall.shopping.dto.HomePageResponse;
import com.mall.shopping.dto.HomePageResponseByXdx;
import com.mall.user.annotation.Anonymous;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * xdx
 * 2020/12/21
 * 21:43
 */

@RestController
@Slf4j
@Anonymous
public class HomePageController {
    @Reference(check = false)
    IHomeService iHomeService;

    @Anonymous
    @RequestMapping("shopping/homepage")
    public ResponseData homepage() {

        HomePageResponse homepage = iHomeService.homepage();
        ResponseData<Object> objectResponseData = new ResponseData<>();
        objectResponseData.setSuccess(true);
        objectResponseData.setTimestamp(new Date().getTime());
        objectResponseData.setCode(200);
        objectResponseData.setMessage("success");
//注意前端需要的json字符串的结构，结构不对是识别不出的
        HomePageResponseByXdx home = new HomePageResponseByXdx();
        home.setPanelContentItemDtos(homepage.getPanelContentItemDtos());

        objectResponseData.setResult(home.getPanelContentItemDtos());
        return objectResponseData;
    }

}
